package org.feng.service.impl;

import jakarta.annotation.Resource;
import org.feng.entity.Tables;
import org.feng.manager.InformationSchemaManager;
import org.feng.service.TableService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 表服务实现
 *
 * @author mcp
 * @version 1.0
 * @since 2025-05-07 14:01
 */
@Service
public class TableServiceImpl implements TableService {

    @Resource
    private InformationSchemaManager informationSchemaManager;

    @Override
    @Tool(name = "findAllTableNames", description = "根据schema或数据库名，查询当前数据库下的所有可用的表名和表备注")
    public List<Tables> findAllTableNames(@ToolParam(description = "表的schema，即数据库名") String tableSchema) {
        return informationSchemaManager.findAllTableNames(tableSchema);
    }

    @Override
    @Tool(name = "findAllSchemaNames", description = "查询当前所有可用的schema或数据库名")
    public List<String> findAllSchemaNames() {
        return informationSchemaManager.findAllSchemaNames();
    }

    @Override
    @Tool(name = "getCreateTableStatement", description = "根据schema和表名，查询当前数据库下的对应数据库表创建语句")
    public Map<String, Object> getCreateTableStatement(@ToolParam(description = "表的schema，即数据库名")String tableSchema, @ToolParam(description = "表名") String tableName) {
        return informationSchemaManager.getCreateTableStatement(tableSchema, tableName);
    }
}


